@echo off

if q%1q == qq (
   echo Usage: %0 branch [mailto]
   goto :Eof
)

setlocal 
set branch=%1
set mailto=%2

set projectname=impax-client-setup
set sandboxdir=D:\sandbox
set buildmodule=impax-client-setup

set subject="build logs for %branch%"

if q%branch%q==qmainq (
   set tag=main
) else (
  set tag=%projectname%_%branch%
)

set projectdir=%sandboxdir%\%projectname%_%branch%
set srcdir=%projectdir%\src
set logfile=%projectdir%\buildlog_%branch%.txt

call "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat"

if NOT EXIST %srcdir% (
   cd /d %sandboxdir%
   echo create sandbox %projectname% %tag%
   scm-create-sandbox %projectname% %tag% 2>&1
) else (
  echo update from source | tee %logfile%
  cd /d %srcdir%
  scm-update-sandbox -clean 2>&1 | tee -a %logfile%
)

cd /d %srcdir%\%buildmodule%
echo build everything | tee -a %logfile%
ant buildalldebug 2>&1 | tee -a %logfile%

goto mail

:error
  set subject="error building %branch"   
  goto mail

:mail

if not "q%mailto%q" == "qq" (
mail_build_log %logfile% "Client" %branch% %mailto%
)
